package com.amit;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.catalina.connector.Request;



public class TestServlet extends HttpServlet {
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		HttpSession session=request.getSession();
		ServletContext ctx=session.getServletContext();
		
		//1.string,wrapper,and date
		
		
		request.setAttribute("EM", "amit@gmail.com");
		session.setAttribute("PH", new Long(12345));
		ctx.setAttribute("DOB", new Date());
		
		//2.collection of string,wrappers and date.
		ArrayList<Integer> al=new ArrayList<Integer>();
		al.add(new Integer(11));
		al.add(new Integer(22));
		al.add(new Integer(33));
		al.add(new Integer(44));
		al.add(new Integer(55));
		
		request.setAttribute("AL", al);
		String str[]={"dd","ss","jlc","sri"};
		session.setAttribute("STR", str);
		
		//3.collection of collections()
		
		ArrayList<ArrayList> al1=new ArrayList<ArrayList>();
		al1.add(al);
		al1.add(al);
		al1.add(al);
		
		request.setAttribute("AL1", al1);
		
		//4.custom or user defined class object
		
		Address add=new Address("HMT MAIN ROad", "Blore");
		Account acc=new Account(101, "Saving", 9999.9,add);
		
		Customer cust=new Customer(99, "amit", "amit@gmail.com", 9999, acc);
		session.setAttribute("CUST", cust);
		
		//5.collection of user defined class object
		
		ArrayList<Customer> cs=new ArrayList<Customer>();
		cs.add(cust);
		cs.add(cust);
		cs.add(cust);
		cs.add(cust);
		cs.add(cust);
		session.setAttribute("CS", cs);
		
	//6 Map object
		
		HashMap<String, String> hm=new HashMap<String, String>();
		hm.put("sid", "11");
		hm.put("sname", "sri");
		hm.put("email", "sri@jlc.com");
		session.setAttribute("HM", hm);
		
	//7 collection of Map Object
		ArrayList<HashMap<String, String>> al2=new ArrayList<HashMap<String,String>>();
		al2.add(hm);
		al2.add(hm);
		al2.add(hm);
		request.setAttribute("AL2", al2);
		
		RequestDispatcher rd=request.getRequestDispatcher("show.jsp");
		rd.forward(request, response);
		
		
	
	}
	
	

}
